<ul class="breadcrumb">
	<li><a href="/admin">Dashboard</a><span class="divider">&raquo;</span></li>
	<li><a href="/admin/products">Manager Product</a><span class="divider">&raquo;</span></li>
	<li class="active"><?php echo isset($this->data[$als]['id']) ? 'Edit' : 'Add' ; ?> Product</li>
</ul>

<div class="row-fluid">
	<div class="span12">
		<div class="nonboxy-widget">
			<div class="widget-head">
				<h5><i class="color-icons add_co"></i><?php echo isset($this->data[$als]['id']) ? 'Edit' : 'Add' ; ?> Product</h5>
			</div>

			<?php echo $this->Session->flash(); ?>

			<div class="widget-content">
				<div class="widget-box">

					<?php echo $this->Form->create($als, array('class' => 'form-horizontal well', 'type' => 'file'));?>
						<fieldset>
							<div class="control-group">
								<label class="control-label">Category</label>
								<div class="controls">
									<?php echo $this->Form->input('id', array('type' => 'hidden', 'value' => isset($this->data[$als]['id']) ? $this->data[$als]['id'] : ''));?>
									<?php echo $this->Form->input('category_id', array('div' => false, 'label' => false, 'options' => $categories, 'class' => 'span4'));?>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label">Name</label>
								<div class="controls">
									<?php echo $this->Form->input('name', array('div' => false, 'label' => false, 'placeholder' => 'Input product', 'class' => 'span4'));?>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label">Price (USD)</label>
								<div class="controls">
									<?php echo $this->Form->input('price', array('type' => 'text', 'div' => false, 'label' => false, 'placeholder' => 'Input price', 'class' => 'span4'));?>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label">Discounts (%)</label>
								<div class="controls">
									<?php echo $this->Form->input('discounts', array('type' => 'text', 'div' => false, 'label' => false, 'placeholder' => 'Input discounts', 'class' => 'span4'));?>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label">Images</label>
								<div class="controls">
									<?php echo $this->Form->input('image', array( 'type' => 'file', 'name' => 'data[Product][images][]', 'multiple' => true, 'div' => false, 'label' => false, 'class' => 'input-file'));?>

									<!--
									<span class="attrs add icon-plus" title="Thêm" onclick="addrow($(this))"></span>
									<span class="attrs del icon-remove hide" title="Xóa" onclick="deleterow($(this))"></span>
									-->
								</div> <br/>

								<?php if(!empty($images)) foreach($images as $img):?>
								<div class="controls">
									<?php echo $this->Form->input('images_del', array('type' => 'hidden', 'name' => 'data[Product][images_old][]', 'value' => $img['ProductImage']['id']));?>
									<?php echo $this->Form->input('images_del', array('type' => 'hidden', 'name' => 'data[Product][images_del][]'));?>
									<label class="checkbox">
										<input type="checkbox" onclick="removeImage($(this))" imgid="<?php echo $img['ProductImage']['id']?>" value="<?php echo $img['ProductImage']['id']?>" name="">Remove
									</label>
									<img src="<?php echo PUBLIC_THUMB_SHOW.$img['ProductImage']['image']; ?>" style="width:400px; margin-bottom:15px;"/>
								</div>
								<?php endforeach;?>
							</div>

							<div class="control-group">
								<label class="control-label">Decription</label>
								<div class="controls">
									<?php echo $this->Form->input('desc', array( 'type' => 'textarea', 'div' => false, 'label' => false, 'placeholder' => 'Input content', 'class' => 'span6', 'row' => 3));?>
								</div>
							</div>

						</fieldset>
						<div class="form-actions">
							<button class="btn btn-primary" type="submit">Save</button>
							<a href="/admin/products" class="btn">Cancel</a>
						</div>
					<?php echo $this->Form->end( ); ?>
				</div>
			</div>

		</div>
	</div>
</div>

<!--================================-->
<script>

$(document).ready(function(){

});




/**
 *
 * checked remove image
 *
 **/
function removeImage(obj)
{
	var _hidden = obj.parent().prev();
	var imgid = obj.attr('imgid');

	if(obj.is(":checked")) {
		_hidden.val(imgid).attr('value', imgid);
	} else {
		_hidden.val('').attr('value', '');
	}
}


/**
 *
 * Add row
 *
 **/
function addrow(btn)
{
	var obj = btn.closest('.controls');
	var newObj = obj.clone();

	btn.addClass('hide').next().removeClass('hide');

	newObj.find('.del').removeClass('hide');
	newObj.find('.error-message').remove();

	obj.after(newObj);
}

/**
 *
 * Delete row
 *
 **/
function deleterow(btn)
{
	var obj = btn.closest('.controls');
	var parent = obj.parent();
	obj.remove();

	var items = parent.find('.controls');

	if(items.length <= 1) {
		items.find('.del').addClass('hide');
		items.find('.add').removeClass('hide');
	} else {
		items.last().find('.add').removeClass('hide');
	}


}


</script>